# 第一阶段：构建 Vue 项目
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:18.20.8-alpine3.20 AS build

# 设置工作目录
WORKDIR /app

# 复制项目文件到容器
COPY . .

RUN npm config set registry https://registry.npmmirror.com && \
    yarn config set registry https://registry.npmmirror.com && \
    yarn install && \
    yarn build

# 第二阶段：使用 Nginx 发布静态文件
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine3.20

# 创建工作目录
WORKDIR /app

# 从第一阶段复制构建好的静态文件到 Nginx 目录
COPY --from=build /app/dist /app

# 复制 Nginx 配置文件
COPY nginx.conf /etc/nginx/nginx.conf

# 暴露 80 端口
EXPOSE 80

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]